<template>
  <div class="app-container" style="padding: 20px">
    <!--搜索栏-->
    <el-row :gutter="15" class="mb8">
      <el-col :span="1.5">
        <el-button
          icon="el-icon-plus"
          plain
          size="mini"
          @click="handleDeviceAdd"
          v-hasPermi="['maintenance:device:add']"
          >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          icon="el-icon-download"
          @click="handleExport"
          v-hasPermi="['maintenance:device:export']"
          >导出</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button icon="el-icon-plus" plain size="mini" @click="authorizedDevice"
          v-hasPermi="['maintenance:device:add']">授权设备
        </el-button>
      </el-col> -->
      <el-form
        :model="queryParams"
        ref="queryParamsRef"
        label-width="70px"
        @submit.prevent
        inline
        class="el-form-search"
      >
        <!--设备名称-->
        <el-form-item
          label="设备名称"
          prop="devName"
          class="el-form-search-item"
        >
          <el-input
            clearable
            placeholder="设备名称"
            v-model.trim="queryParams.devName"
          ></el-input>
        </el-form-item>

        <!-- 地区 -->
        <!-- <el-form-item
          class="el-form-search-item"
          label="地区"
          prop="areaNum"
        >
          <treeselect
            v-model="queryParams.areaNum"
            :normalizer="normalizer"
            :options="areaOptions"
            placeholder="选择地区"
            style="width: 180px"
          />
        </el-form-item> -->

        <!-- 下拉框 -->
        <el-form-item
          label="变电站"
          prop="substationNum"
          class="el-form-search-item"
        >
          <el-select
            clearable
            placeholder="变电站"
            v-model="queryParams.substationNum"
          >
            <el-option
              v-for="item in substationOptions"
              :key="item.num"
              :value="item.num"
              :label="item.substationName"
            ></el-option>
          </el-select>
        </el-form-item>

        <!-- 设备状态 -->
        <el-form-item
          label="设备状态"
          prop="devStatus"
          class="el-form-search-item"
        >
          <el-select
            clearable
            placeholder="设备状态"
            v-model="queryParams.devStatus"
          >
            <el-option
              v-for="dict in devStatusOptions"
              :key="dict.num"
              :value="dict.code"
              :label="dict.name"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item class="el-form-search-item">
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button size="mini" icon="el-icon-refresh" @click="handleRefresh"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-row>

    <!--展示列表-->
    <el-table
      ref="deiveAuthorize"
      :data="deviceList"
      :height="tableHeight"

      v-loading="loading"
      border
      stripe
      @expand-change="handleExpandChange"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="40" /> -->
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-table
            :data="props.row.channelList"
            border
            :header-cell-style="{ background: '#dadde7', textSize: '14px' }"
            :highlight-current-row="false"
            stripe
            v-if="props.row.channelList"
          >
            <el-table-column width="40"></el-table-column>

            <el-table-column
              label="通道序号"
              prop="channelNum"
              align="center"
            ></el-table-column
            ><el-table-column
              label="通道名称"
              prop="channelName"
              align="center"
            ></el-table-column>
            <el-table-column
              label="并网点"
              prop="connectionPoint.connectionPointName"
              width="150"
              align="center"
            ></el-table-column>
            <el-table-column
              label="额定电压"
              prop="ratedVol.name"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="电压等级"
              prop="volLevel.name"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="接线方式"
              prop="wiringMethod.name"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="电压变比"
              prop="voltageRatio"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="电流变比"
              prop="currentRatio"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="对应电压"
              prop="matchVoltage"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="接入方式"
              prop="accessMethod.name"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="基准短路容量"
              prop="baseShortCirCap"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="最小短路容量"
              prop="minShortCirCap"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="用电协议容量"
              prop="eServAgCap"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="用电设备容量"
              prop="dEquipCap"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="用电上限阈值"
              prop="voltageUpperLimit"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="用电下限阈值"
              prop="voltageLowerLimit"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="电压中断阈值"
              prop="voltageLnterThr"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column
              label="通道数据源"
              prop="chInfoSource"
              width="100"
              align="center"
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="操作"
              width="150"
              fixed="right"
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="mini"
                  icon="el-icon-edit"
                  @click="handelChannelEdit(scope.row, props.row)"
                  v-hasPermi="['maintenance:channel:edit']"
                  >修改
                </el-button>
                <el-button
                  type="text"
                  size="mini"
                  icon="el-icon-delete"
                  @click="handelChannelDel(scope.row)"
                  v-hasPermi="['maintenance:channel:remove']"
                  >删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        label="#"
        type="index"
        width="50"
        :resizable="false"
      >
        <template slot-scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="设备名称"
        prop="devName"
        :resizable="false"
        show-overflow-tooltip
        width="150"
      ></el-table-column>
      <el-table-column
        align="center"
        label="设备编号"
        prop="devNum"
        :resizable="false"
        show-overflow-tooltip
        width="120"
      ></el-table-column>
      <!-- <el-table-column
        align="center"
        label="客户"
        prop="customer.companyName"
      ></el-table-column> -->
      <el-table-column
        align="center"
        label="所属地区"
        prop="substation.ancestorNames"
        :resizable="false"
        show-overflow-tooltip
        width="130"
      ></el-table-column>
      <el-table-column
        align="center"
        label="所属变电站"
        show-overflow-tooltip
        width="100"
        prop="substation.substationName"
        :resizable="false"
      ></el-table-column>
      <el-table-column
        align="center"
        label="设备状态"
        prop="deviceStatus.name"
        width="80"
        :resizable="false"
      >
        <template slot-scope="scope">
          <el-tag :type="statusFormat(scope.row.devStatus)">{{
            scope.row.deviceStatus.name
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="通讯状态"
        prop="communicationStatus.name"
        width="80"
        :resizable="false"
      >
        <template slot-scope="scope">
          <el-tag :type="statusFormat(scope.row.communicationStatusNum)">{{
            scope.row.communicationStatus.name
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="设备型号"
        show-overflow-tooltip
        prop="devModel.name"
        :resizable="false"
      ></el-table-column>

      <el-table-column
        align="center"
        prop="terminalIdentifier"
        label="终端识别码"
      ></el-table-column>
      <!-- <el-table-column
        align="center"
        label="设备描述"
        prop="devDesc"
        :resizable="false"
      ></el-table-column> -->
      <el-table-column
        align="center"
        label="存储间隔"
        prop="storageInterval"
        :resizable="false"
        width="90"
      >
      </el-table-column>
      <el-table-column
        align="center"
        label="SIM卡"
        show-overflow-tooltip
        prop="simCard.phone"
        :resizable="false"
        width="115"
      ></el-table-column>

      <el-table-column
        align="center"
        label="入网方式"
        prop="connMethod.name"
        width="80"
        :resizable="false"
      ></el-table-column>
      <!-- <el-table-column
        align="center"
        label="MAC地址"
        prop="devMac"
        :resizable="false"
      ></el-table-column> -->
      <!-- <el-table-column
        align="center"
        label="安装位置"
        prop="installationSite"
        :resizable="false"
      ></el-table-column> -->

      <!-- <el-table-column align="center" label="数据地址" prop="devInfoSource" show-overflow-tooltip :resizable="false">
      </el-table-column> -->

      <el-table-column
        align="center"
        label="投运日期"
        prop="putDate"
        :resizable="false"
        show-overflow-tooltip
        width="120"
      ></el-table-column>

      <el-table-column
        align="center"
        label="操作"
        width="220"
        :resizable="false"
        class-name="operation-column"
      >
        <template slot-scope="scope">
          <el-button
            icon="el-icon-view"
            size="mini"
            type="text"
            @click="handleDeviceView(scope.row)"
            v-hasPermi="['maintenance:deviceDetail:examine']"
            >查看
          </el-button>
          <el-button
            icon="el-icon-plus"
            size="mini"
            type="text"
            @click="handelChannelAdd(scope.row)"
            v-hasPermi="['maintenance:deviceDetail:examine']"
            >通道
          </el-button>
          <el-button
            icon="el-icon-edit"
            size="mini"
            type="text"
            @click="handleDeviceEdit(scope.row)"
            v-hasPermi="['maintenance:deviceDetail:examine']"
            >修改
          </el-button>
          <el-button
            icon="el-icon-delete"
            size="mini"
            type="text"
            @click="handleDeviceDelete(scope.row)"
            v-hasPermi="['maintenance:deviceDetail:examine']"
            >删除
          </el-button>

          <!-- <el-dropdown>
            <el-button type="text" size="mini" style="margin-left:10px">
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleDeviceEdit(scope.row)" v-hasPermi="['maintenance:device:edit']">
                <i class="el-icon-edit"></i> 修改
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleDeviceDelete(scope.row)"
                v-hasPermi="['maintenance:device:remove']">
                <i class="el-icon-delete"></i> 删除
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown> -->
          <!--          <el-row :gutter="15">-->
          <!--            <el-col>-->

          <!--              <el-button-->
          <!--                plain-->
          <!--                icon="el-icon-plus"-->
          <!--                size="mini"-->
          <!--                type="text"-->
          <!--                @click="handelChannelAdd(scope.row)"-->
          <!--                v-hasPermi="['maintenance:channel:add']"-->
          <!--              >通道-->
          <!--              </el-button>-->
          <!--            </el-col>-->
          <!--            <el-col>-->
          <!--              <el-button-->
          <!--                icon="el-icon-edit"-->
          <!--                size="mini"-->
          <!--                type="text"-->
          <!--                @click="handleDeviceEdit(scope.row)"-->
          <!--                v-hasPermi="['maintenance:device:edit']"-->
          <!--              >修改-->
          <!--              </el-button>-->
          <!--              <el-button-->
          <!--                icon="el-icon-delete"-->
          <!--                size="mini"-->
          <!--                type="text"-->
          <!--                @click="handleDeviceDelete(scope.row)"-->
          <!--                v-hasPermi="['maintenance:device:remove']"-->
          <!--              >删除-->
          <!--              </el-button>-->
          <!--            </el-col>-->
          <!--          </el-row>-->
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页控件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 设备对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      v-dialogDrag
      :close-on-click-modal="false"
      width="800px"
    >
      <el-form
        ref="deviceFormDataRef"
        :model="deviceFormData"
        label-width="100px"
        :rules="deviceRule"
        label-position="left"
      >
        <!--第一行-->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="设备名称" prop="devName">
              <el-input
                v-model="deviceFormData.devName"
                placeholder="设备名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备编号" prop="devNum">
              <el-input
                v-model="deviceFormData.devNum"
                placeholder="设备编号"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <!--第二行-->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="设备型号" prop="devModelNum">
              <el-select
                clearable
                filterable
                placeholder="请选择设备型号"
                v-model="deviceFormData.devModelNum"
                class="from-select"
              >
                <el-option
                  v-for="item in devModelOptions"
                  :key="item.num"
                  :value="item.num"
                  :label="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="设备状态"
              prop="devStatus"
              class="el-form-search-item"
            >
              <el-select
                clearable
                filterable
                placeholder="设备状态"
                v-model="deviceFormData.devStatus"
                class="from-select"
              >
                <el-option
                  v-for="dict in devStatusOptions"
                  :key="dict.num"
                  :value="dict.code"
                  :label="dict.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!--第五行-->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="变电站" prop="substationNum">
              <el-select
                clearable
                filterable
                placeholder="请选择变电站"
                v-model="deviceFormData.substationNum"
                class="from-select"
              >
                <el-option
                  v-for="item in substationOptions"
                  :key="item.num"
                  :value="item.num"
                  :label="item.substationName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备排序" prop="sort">
              <!-- <el-autocomplete v-model="deviceFormData.sort" :fetch-suggestions="querySearch" @select="handleSelect"
                placeholder="请输入排序" :trigger-on-focus="true" class="from-select">
                <template #default="{ item }">
                  <div class="autocomplete-item-disabled">{{ item.value }}</div>
                </template>
              </el-autocomplete> -->

              <el-input
                v-model="deviceFormData.sort"
                placeholder="请输入排序"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="入网方式" prop="connMode">
              <el-select
                clearable
                filterable
                v-model="deviceFormData.connMode"
                placeholder="入网方式"
                class="from-select"
              >
                <el-option
                  v-for="dict in connModeOptions"
                  :key="dict.code"
                  :label="dict.name"
                  :value="dict.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备MAC地址" prop="devMac">
              <el-input
                v-model="deviceFormData.devMac"
                placeholder="设备MAC地址"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="投运日期" prop="putDate">
              <el-date-picker
                v-model="deviceFormData.putDate"
                type="date"
                placeholder="投运日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="存储间隔" prop="storageInterval">
              <el-input
                v-model="deviceFormData.storageInterval"
                placeholder="存储间隔"
              >
                <template slot="append">秒</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item
              label="通信规约"
              prop="communicationProtocolNum"
              clearable
              filterable
              class="from-select"
            >
              <el-select
                v-model="deviceFormData.communicationProtocolNum"
                placeholder="通信规约"
              >
                <el-option
                  v-for="dict in commProtocolOptions"
                  :key="dict.code"
                  :label="dict.name"
                  :value="dict.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安装位置" prop="installationSite">
              <el-input
                v-model="deviceFormData.installationSite"
                placeholder="安装位置"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第六行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="数据地址" prop="devInfoSource">
              <el-input
                v-model="deviceFormData.devInfoSource"
                placeholder="数据地址"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="SIM电话卡" prop="simCardNum">
              <el-select
                clearable
                filterable
                placeholder="请选择SIM卡"
                v-model="deviceFormData.simCardNum"
                class="from-select"
              >
                <el-option
                  v-for="item in simCardOptions"
                  :key="item.num"
                  :value="item.num"
                  :label="item.phone"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第七行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--设备描述-->
            <el-form-item label="设备描述" prop="devDesc">
              <el-input
                v-model.trim="deviceFormData.devDesc"
                :maxlength="100"
                :rows="2"
                clearable
                placeholder="设备描述"
                resize="none"
                show-word-limit
                type="textarea"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="终端识别码"
              prop="terminalIdentifier"
              style="width: 100%"
            >
              <el-input
                v-model="deviceFormData.terminalIdentifier"
                placeholder="终端识别码"
                class="custom-input"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="submitDeviceFormData"
          v-show="hasPermission"
          >提交</el-button
        >
        <el-button @click="deviceClose">取消</el-button>
      </div>
    </el-dialog>

    <!-- 通道对话框 -->
    <el-dialog
      :title="channelTitle"
      :visible.sync="channelOpen"
      :close-on-click-modal="false"
      v-dialogDrag
      width="800px"
      append-to-body
    >
      <el-form
        :model="channelFormData"
        :rules="channelFormDataRules"
        ref="channelFormDataRef"
        label-width="100px"
        @submit.prevent
        label-position="left"
      >
        <!-- 第一行 -->
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="名称" prop="channelName">
              <el-input
                clearable
                placeholder="输入通道名称"
                v-model.trim="channelFormData.channelName"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第九行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="通道数据源" prop="chInfoSource">
              <el-input
                clearable
                placeholder="输入通道数据源"
                v-model.trim="channelFormData.chInfoSource"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通道序号" prop="channelNum">
              <el-select
                clearable
                filterable
                placeholder="请选择序号"
                v-model="channelFormData.channelNum"
                class="from-select"
              >
                <el-option
                  v-for="item in sortOptions"
                  :key="item.id"
                  :value="item.id"
                  :label="item.sort"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="设备" prop="deviceNum">
              <el-select
                clearable
                filterable
                placeholder="请选择设备"
                v-model="channelFormData.deviceNum"
                class="from-select"
                disabled
              >
                <el-option
                  v-for="item in deviceOptions"
                  :key="item.num"
                  :value="item.num"
                  :label="item.devName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="并网点" prop="connectionPointNum">
              <el-select
                clearable
                filterable
                placeholder="请选择并网点"
                v-model="channelFormData.connectionPointNum"
                class="from-select"
              >
                <el-option
                  v-for="item in connectionPointOptions"
                  :key="item.num"
                  :value="item.num"
                  :label="
                    item.substation.substationName +
                    '-' +
                    item.connectionPointName
                  "
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第二行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="接线方式" prop="wiringMeth">
              <el-select
                clearable
                filterable
                placeholder="接线方式"
                v-model="channelFormData.wiringMeth"
                class="from-select"
              >
                <el-option
                  v-for="item in wiringMethodOptions"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接入方式" prop="accessMode">
              <el-select
                clearable
                filterable
                placeholder="接入方式"
                v-model="channelFormData.accessMode"
                class="from-select"
              >
                <el-option
                  v-for="item in accessMethodOptions"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第三行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="额定电压" prop="ratedVoltage">
              <el-select
                clearable
                filterable
                placeholder="额定电压"
                v-model="channelFormData.ratedVoltage"
                class="from-select"
              >
                <el-option
                  v-for="item in ratedVoltageOptions"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电压等级" prop="voltageLevel">
              <el-select
                clearable
                filterable
                placeholder="电压等级"
                v-model="channelFormData.voltageLevel"
                class="from-select"
                @change="handleVoltageLevel"
              >
                <el-option
                  v-for="item in voltageLevelOptions"
                  :key="item.code"
                  :value="item.code"
                  :label="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第四行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="电压变比" prop="voltageRatio">
              <el-input
                clearable
                placeholder="输入电压变比"
                v-model.trim="channelFormData.voltageRatio"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电流变比" prop="currentRatio">
              <el-input
                clearable
                placeholder="输入电流变比"
                v-model.trim="channelFormData.currentRatio"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第五行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="对应电压" prop="matchVoltage">
              <el-select
                clearable
                placeholder="对应电压"
                v-model="channelFormData.matchVoltage"
                class="from-select"
              >
                <el-option
                  v-for="item in matchVoltageOptions"
                  :key="item.dictValue"
                  :value="item.dictValue"
                  :label="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="基准短路容量" prop="baseShortCirCap">
              <el-input
                clearable
                placeholder="输入基准短路容量"
                v-model.trim="channelFormData.baseShortCirCap"
              >
                <template slot="append">MVA</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第六行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="电压上限阈值" prop="voltageUpperLimit">
              <el-input
                clearable
                placeholder="输入电压上限阈值"
                v-model.trim="channelFormData.voltageUpperLimit"
              >
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最小短路容量" prop="minShortCirCap">
              <el-input
                clearable
                placeholder="输入最小短路容量"
                v-model.trim="channelFormData.minShortCirCap"
              >
                <template slot="append">MVA</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第七行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="电压下限阈值" prop="voltageLowerLimit">
              <el-input
                clearable
                placeholder="输入电压下限阈值"
                v-model.trim="channelFormData.voltageLowerLimit"
              >
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用电协议容量" prop="eServAgCap">
              <el-input
                clearable
                placeholder="输入用电协议容量"
                v-model.trim="channelFormData.eServAgCap"
              >
                <template slot="append">MVA</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第八行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="电压中断阈值" prop="voltageLnterThr">
              <el-input
                clearable
                placeholder="输入电压中断阈值"
                v-model.trim="channelFormData.voltageLnterThr"
              >
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="用电设备容量" prop="dEquipCap">
              <el-input
                clearable
                placeholder="输入用电设备容量"
                v-model.trim="channelFormData.dEquipCap"
              >
                <template slot="append">MVA</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <h3 v-if="cxdzFlag">越限定值</h3>
      <el-table border :data="cxdzList" v-if="cxdzFlag">
        <el-table-column align="center" label="#" type="index" width="50">
        </el-table-column>
        <el-table-column align="center" prop="type" label="定值等级">
          <template slot-scope="scope">
            {{ getChangeType(scope.row.type) }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="freqU"
          label="频率上限"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="freqL"
          label="频率下限"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="cos"
          label="功率因数"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="u2u1"
          label="电压不平衡度"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="u0"
          label="零序电压"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="u1"
          label="正序电压"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="u2"
          label="负序电压"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="i2i1"
          label="电流不平衡度"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="i0"
          label="零序电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="i1"
          label="正序电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="i2"
          label="负序电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="bd"
          label="电压波动"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="pch"
          label="电压偏差上限"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="pcl"
          label="电压偏差下限"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="plt"
          label="电压长时闪变"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="pst"
          label="电压短时闪变"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="thdu"
          label="电压总畸变率"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="hruo"
          label="电压奇次谐波"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="hruj"
          label="电压偶次谐波"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="uwu"
          label="备用1"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="uwl"
          label="备用2"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="uwi"
          label="备用3"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru2"
          label="2次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru3"
          label="3次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru4"
          label="4次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru5"
          label="5次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru6"
          label="6次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru7"
          label="7次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru8"
          label="8次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru9"
          label="9次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru10"
          label="10次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru11"
          label="11次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru12"
          label="12次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru13"
          label="13次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru14"
          label="14次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru15"
          label="15次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru16"
          label="16次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru17"
          label="17次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru18"
          label="18次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru19"
          label="19次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru20"
          label="20次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru21"
          label="21次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru22"
          label="22次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru23"
          label="23次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru24"
          label="24次谐波电流"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="ihru25"
          label="25次谐波电流"
        ></el-table-column>
        <el-table-column align="center" label="操作" fixed="right" width="120">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="mini"
              icon="el-icon-edit"
              @click="handleCxdzEdit(scope.row)"
              >编辑</el-button
            >
            <el-button
              type="text"
              size="mini"
              icon="el-icon-refresh"
              @click="handleCxdzRefresh(scope.row)"
              >重置</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" v-if="cxdzFlag"
          >生成定值
        </el-button>
        <el-button
          type="primary"
          size="mini"
          v-show="hasPermission"
          @click="submitChannelFormData"
          >提交
        </el-button>
        <el-button size="mini" @click="channelClose">取消</el-button>
      </div>
    </el-dialog>

    <!-- 授权设备给用户 -->
    <el-dialog title="设备授权" :visible.sync="authorizeOpen">
      <el-form :model="authorizeForm" label-width="100px">
        <el-form-item label="授权用户" required>
          <el-select v-model="authorizeForm.userId" placeholder="请选择用户">
            <el-option
              v-for="(item, index) in userList"
              :key="index"
              :label="item.nickName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-table :data="authorizedDeviceList" border>
        <el-table-column
          align="center"
          prop="devName"
          label="设备名称"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="devNum"
          label="设备编号"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="devModelNum"
          label="设备型号"
        ></el-table-column>
        <el-table-column
          align="center"
          label="设备状态"
          prop="deviceStatus.name"
          width="80"
          :resizable="false"
        >
          <template slot-scope="scope">
            <el-tag :type="statusFormat(scope.row.devStatus)">{{
              scope.row.deviceStatus.name
            }}</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAuthorizedForm"
          >确认授权</el-button
        >
        <el-button @click="authorizeOpen = false">取消</el-button>
      </div>
    </el-dialog>

    <!-- cxdz对话框 -->
    <el-dialog
      :title="cxdzTitle"
      :visible.sync="cxdzOpen"
      :close-on-click-modal="false"
      v-dialogDrag
      width="850px"
    >
      <el-form
        ref="cxdzFormDataRef"
        :model="cxdzFormData"
        label-width="100px"
        :rules="cxdzRule"
        style="max-height: 400px; overflow-y: auto; overflow-x: hidden"
      >
        <!-- <el-row :gutter="15">
          <el-col :span="12">

            <el-form-item
              label="定值等级"
              prop="type"
            >
              <el-select
                clearable
                placeholder="定值等级"
                v-model="cxdzFormData.type"
              >
                <el-option
                  v-for="dict in cxdzAlarmOption"
                  :key="dict.dictValue"
                  :value="dict.dictValue"
                  :label="dict.dictLabel"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row> -->
        <!-- 第二行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--频率上限-->
            <el-form-item label="频率上限" prop="freqU">
              <el-input
                clearable
                placeholder="频率上限"
                v-model.trim="cxdzFormData.freqU"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--频率下限-->
            <el-form-item label="频率下限" prop="freqL">
              <el-input
                clearable
                placeholder="频率下限"
                v-model.trim="cxdzFormData.freqL"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第三行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--功率因数-->
            <el-form-item label="功率因数" prop="cos">
              <el-input
                clearable
                placeholder="功率因数"
                v-model.trim="cxdzFormData.cos"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--电压不平衡度-->
            <el-form-item label="电压不平衡度" prop="u2u1">
              <el-input
                clearable
                placeholder="电压不平衡度"
                v-model.trim="cxdzFormData.u2u1"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第四行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--零序电压-->
            <el-form-item label="零序电压" prop="u0">
              <el-input
                clearable
                placeholder="零序电压"
                v-model.trim="cxdzFormData.u0"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--正序电压-->
            <el-form-item label="正序电压" prop="u1">
              <el-input
                clearable
                placeholder="正序电压"
                v-model.trim="cxdzFormData.u1"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第五行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--负序电压-->
            <el-form-item label="负序电压" prop="u2">
              <el-input
                clearable
                placeholder="负序电压"
                v-model.trim="cxdzFormData.u2"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--电流不平衡度-->
            <el-form-item label="电流不平衡度" prop="i2i1">
              <el-input
                clearable
                placeholder="电流不平衡度"
                v-model.trim="cxdzFormData.i2i1"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第六行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--零序电流-->
            <el-form-item label="零序电流" prop="i0">
              <el-input
                clearable
                placeholder="零序电流"
                v-model.trim="cxdzFormData.i0"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--正序电流-->
            <el-form-item label="正序电流" prop="i1">
              <el-input
                clearable
                placeholder="正序电流"
                v-model.trim="cxdzFormData.i1"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第七行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--负序电流-->
            <el-form-item label="负序电流" prop="i2">
              <el-input
                clearable
                placeholder="负序电流"
                v-model.trim="cxdzFormData.i2"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--电压波动-->
            <el-form-item label="电压波动" prop="bd">
              <el-input
                clearable
                placeholder="电压波动"
                v-model.trim="cxdzFormData.bd"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第八行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--电压偏差上限-->
            <el-form-item label="电压偏差上限" prop="pch">
              <el-input
                clearable
                placeholder="电压偏差上限"
                v-model.trim="cxdzFormData.pch"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--电压偏差下限-->
            <el-form-item label="电压偏差下限" prop="pcl">
              <el-input
                clearable
                placeholder="电压偏差下限"
                v-model.trim="cxdzFormData.pcl"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第九行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--电压长时闪变-->
            <el-form-item label="电压长时闪变" prop="plt">
              <el-input
                clearable
                placeholder="电压长时闪变"
                v-model.trim="cxdzFormData.plt"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--电压短时闪变-->
            <el-form-item label="电压短时闪变" prop="pst">
              <el-input
                clearable
                placeholder="电压短时闪变"
                v-model.trim="cxdzFormData.pst"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第十行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--电压总畸变率-->
            <el-form-item label="电压总畸变率" prop="thdu">
              <el-input
                clearable
                placeholder="电压总畸变率"
                v-model.trim="cxdzFormData.thdu"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--电压奇次谐波-->
            <el-form-item label="电压奇次谐波" prop="hruo">
              <el-input
                clearable
                placeholder="电压奇次谐波"
                v-model.trim="cxdzFormData.hruo"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第十一行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--电压偶次谐波-->
            <el-form-item label="电压偶次谐波" prop="hruj">
              <el-input
                clearable
                placeholder="电压偶次谐波"
                v-model.trim="cxdzFormData.hruj"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--备用1-->
            <el-form-item label="备用1" prop="uwu">
              <el-input
                clearable
                placeholder="备用1"
                v-model.trim="cxdzFormData.uwu"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第十二行 -->
        <el-row :gutter="15">
          <el-col :span="12">
            <!--备用2-->
            <el-form-item label="备用2" prop="uwl">
              <el-input
                clearable
                placeholder="备用2"
                v-model.trim="cxdzFormData.uwl"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!--备用3-->
            <el-form-item label="备用3" prop="uwi">
              <el-input
                clearable
                placeholder="备用3"
                v-model.trim="cxdzFormData.uwi"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第十三行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--2次谐波电流-->
            <el-form-item label="2次谐波电流" prop="ihru2">
              <el-input
                clearable
                placeholder="2次谐波电流"
                v-model.trim="cxdzFormData.ihru2"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--3次谐波电流-->
            <el-form-item label="3次谐波电流" prop="ihru3">
              <el-input
                clearable
                placeholder="3次谐波电流"
                v-model.trim="cxdzFormData.ihru3"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--4次谐波电流-->
            <el-form-item label="4次谐波电流" prop="ihru4">
              <el-input
                clearable
                placeholder="4次谐波电流"
                v-model.trim="cxdzFormData.ihru4"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第十四行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--5次谐波电流-->
            <el-form-item label="5次谐波电流" prop="ihru5">
              <el-input
                clearable
                placeholder="5次谐波电流"
                v-model.trim="cxdzFormData.ihru5"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--6次谐波电流-->
            <el-form-item label="6次谐波电流" prop="ihru6">
              <el-input
                clearable
                placeholder="6次谐波电流"
                v-model.trim="cxdzFormData.ihru6"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--7次谐波电流-->
            <el-form-item label="7次谐波电流" prop="ihru7">
              <el-input
                clearable
                placeholder="7次谐波电流"
                v-model.trim="cxdzFormData.ihru7"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十五行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--8次谐波电流-->
            <el-form-item label="8次谐波电流" prop="ihru8">
              <el-input
                clearable
                placeholder="8次谐波电流"
                v-model.trim="cxdzFormData.ihru8"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--9次谐波电流-->
            <el-form-item label="9次谐波电流" prop="ihru9">
              <el-input
                clearable
                placeholder="9次谐波电流"
                v-model.trim="cxdzFormData.ihru9"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--10次谐波电流-->
            <el-form-item label="10次谐波电流" prop="ihru10">
              <el-input
                clearable
                placeholder="10次谐波电流"
                v-model.trim="cxdzFormData.ihru10"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十六行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--11次谐波电流-->
            <el-form-item label="11次谐波电流" prop="ihru11">
              <el-input
                clearable
                placeholder="11次谐波电流"
                v-model.trim="cxdzFormData.ihru11"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--12次谐波电流-->
            <el-form-item label="12次谐波电流" prop="ihru12">
              <el-input
                clearable
                placeholder="12次谐波电流"
                v-model.trim="cxdzFormData.ihru12"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--13次谐波电流-->
            <el-form-item label="13次谐波电流" prop="ihru13">
              <el-input
                clearable
                placeholder="13次谐波电流"
                v-model.trim="cxdzFormData.ihru13"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十七行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--14次谐波电流-->
            <el-form-item label="14次谐波电流" prop="ihru14">
              <el-input
                clearable
                placeholder="14次谐波电流"
                v-model.trim="cxdzFormData.ihru14"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--15次谐波电流-->
            <el-form-item label="15次谐波电流" prop="ihru15">
              <el-input
                clearable
                placeholder="15次谐波电流"
                v-model.trim="cxdzFormData.ihru15"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--16次谐波电流-->
            <el-form-item label="16次谐波电流" prop="ihru16">
              <el-input
                clearable
                placeholder="16次谐波电流"
                v-model.trim="cxdzFormData.ihru16"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十八行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--17次谐波电流-->
            <el-form-item label="17次谐波电流" prop="ihru17">
              <el-input
                clearable
                placeholder="17次谐波电流"
                v-model.trim="cxdzFormData.ihru17"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--18次谐波电流-->
            <el-form-item label="18次谐波电流" prop="ihru18">
              <el-input
                clearable
                placeholder="18次谐波电流"
                v-model.trim="cxdzFormData.ihru18"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--19次谐波电流-->
            <el-form-item label="19次谐波电流" prop="ihru19">
              <el-input
                clearable
                placeholder="19次谐波电流"
                v-model.trim="cxdzFormData.ihru19"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十八行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--20次谐波电流-->
            <el-form-item label="20次谐波电流" prop="ihru20">
              <el-input
                clearable
                placeholder="20次谐波电流"
                v-model.trim="cxdzFormData.ihru20"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--21次谐波电流-->
            <el-form-item label="21次谐波电流" prop="ihru21">
              <el-input
                clearable
                placeholder="21次谐波电流"
                v-model.trim="cxdzFormData.ihru21"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--22次谐波电流-->
            <el-form-item label="22次谐波电流" prop="ihru22">
              <el-input
                clearable
                placeholder="22次谐波电流"
                v-model.trim="cxdzFormData.ihru22"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 第十九行 -->
        <el-row :gutter="15">
          <el-col :span="8">
            <!--23次谐波电流-->
            <el-form-item label="23次谐波电流" prop="ihru23">
              <el-input
                clearable
                placeholder="23次谐波电流"
                v-model.trim="cxdzFormData.ihru23"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--24次谐波电流-->
            <el-form-item label="24次谐波电流" prop="ihru24">
              <el-input
                clearable
                placeholder="24次谐波电流"
                v-model.trim="cxdzFormData.ihru24"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--25次谐波电流-->
            <el-form-item label="25次谐波电流" prop="ihru25">
              <el-input
                clearable
                placeholder="25次谐波电流"
                v-model.trim="cxdzFormData.ihru25"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="submitCxdzFormData"
          v-show="hasPermission"
          >提交</el-button
        >
        <el-button @click="cxdzClose">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  refreshCxdz,
  listCxdz,
  addCxdz,
  editCxdz,
  removeCxdz,
  getCxdzByNum,
} from "@/api/maintenance/cxdz";
import {
  getDeviceListFold,
  getDeviceList,
  addDevice,
  getByNum,
  editDevice,
  removeBatch,
  getDeviceSortList,
} from "@/api/device/device";
import {
  listChannel,
  addChannel,
  getChannelByNum,
  editChannel,
  delChannel,
  getSortList,
} from "@/api/maintenance/channel";
import { listSubstation } from "@/api/maintenance/substation";
import { listDevModel } from "@/api/device/devModel";
import { listCustomer } from "@/api/maintenance/customer";
import { listSimCard } from "@/api/maintenance/simCard";
import { listConnectionPoint } from "@/api/maintenance/connectionPoint";
import { listArea } from "@/api/maintenance/area";

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {
  getConnMethod,
  getCommunicationProtocol,
  getWiringMethod,
  getRatedVol,
  getAccessMethod,
  getVolLevel,
  getDeviceStatus,
} from "@/api/maintenance/dimensionTables";
import { listUser } from "@/api/system/user";
import Cookies from "js-cookie";
import { addDeviceAuthorized } from "@/api/authorization/deviceAuthorized";
export default {
  name: "Index_new",
  components: { Treeselect },
  data() {
    return {
      authorizedDeviceList: [], // 授权设备列表
      /**设备数据 */
      // 表格信息
      tableHeight: "calc(100vh - 200px)",
      loading: false, // 遮罩层
      authorizeOpen: false, // 遮罩层
      authorizeForm: {}, // 遮罩层
      total: 0, //数据总条数
      deviceList: [],
      userList: [],
      ids: [],
      single: true,
      multiple: true,
      devInfoSourceData: "",
      chInfoSourceData: "",

      // 搜索框
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        // orderByColumn: "update_time",
        // isAsc: "ASC",
      },

      //对话框数据
      title: "",
      open: false,
      deviceFormData: {
        sort: "",
      },
      substationOptions: [],
      devModelOptions: [],
      customerOptions: [],
      simCardOptions: [],
      devStatusOptions: [],
      areaOptions: [],
      connModeOptions: [],
      commProtocolOptions: [], //通信规约
      deviceRule: {
        devName: [
          { required: true, message: "设备名称不能为空", trigger: "blur" },
        ],
        devNum: [
          { required: true, message: "设备编号不能为空", trigger: "blur" },
        ],
        devModelNum: [
          { required: true, message: "设备型号不能为空", trigger: "blur" },
        ],
        substationNum: [
          {
            required: true,
            message: "变电站不能为空",
            trigger: "blur",
          },
        ],
        customerNum: [
          {
            required: true,
            message: "客户不能为空",
            trigger: "blur",
          },
        ],
        // sort: [
        //   {
        //     validator: this.validateSortExistence,
        //     trigger: "blur",
        //   }
        // ]
      },

      /**通道数据 */
      // 并网点下拉框数据
      connectionPointOptions: [],
      // 设备下拉框数据
      deviceOptions: [],
      // 电压等级下拉框数据
      voltageLevelOptions: [],
      // 接线方式下拉框数据
      wiringMethodOptions: [],
      // 接入方式下拉框数据
      accessMethodOptions: [],
      // 额定电压下拉框数据
      ratedVoltageOptions: [],
      // 对应电压下拉框数据
      matchVoltageOptions: [],
      // 排序列表
      sortOptions: [],
      //对话框数据
      channelTitle: "",
      channelOpen: false,
      channelFormData: {},
      channelFormDataRules: {
        channelName: [
          { required: true, message: "通道不能为空", trigger: "blur" },
        ],
        channelNum: [
          { required: true, message: "序号不能为空", trigger: "blur" },
        ],
        connectionPointNum: [
          { required: true, message: "并网点不能为空", trigger: "blur" },
        ],
        deviceNum: [
          { required: true, message: "设备不能为空", trigger: "blur" },
        ],
        // 电压变比
        voltageRatio: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        // 电流变比
        currentRatio: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        // 基准短路容量
        baseShortCirCap: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        // 最小短路容量
        minShortCirCap: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        // 用电协议容量
        eServAgCap: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        // 用电设备容量
        dEquipCap: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        voltageUpperLimit: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        voltageLowerLimit: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
        voltageLnterThr: [
          {
            validator: this.formValidation.validateTwoDecimalPlaces,
            message: "请输入两位数字",
            trigger: "blur",
          },
        ],
      },
      /**cxdz数据 */
      cxdzList: [],
      cxdzTitle: "",
      cxdzOpen: false,
      cxdzFormData: {},
      cxdzRule: [],
      cxdzAlarmOption: [],
      deviceSortOptions: [],
      cxdzFlag: false, //cxdz表格是否展示
    };
  },
  computed: {
    statusFormat() {
      return (status) => {
        const statusMap = ["success", "danger", "waring", "info"];
        return statusMap[status] || "";
      };
    },
    // 判断普通管理员是否有权限操作别人的数据
    hasPermission() {
      // 登陆人
      let username = Cookies.get("username");
      let roleName = this.$store.state.user.roles[0];
      if (
        this.deviceFormData &&
        roleName == "common" &&
        username != this.deviceFormData?.createBy &&
        this.title === "修改设备"
      ) {
        return false;
      }

      if (roleName === "general") return false;
      return true;
    },
  },
  created() {
    getDeviceSortList().then((response) => {
      this.deviceSortOptions = response.data.map((item) => String(item.sort));
    });
    console.log(this.$store.state.user.roles);
    this.getList();

    //获取变电站列表
    listSubstation().then((response) => {
      this.substationOptions = response.rows;
    });
    // 接入方式
    // this.getDicts("access_method").then((response) => {
    //   this.connModeOptions = response.data;
    // });
    getConnMethod().then((response) => {
      this.connModeOptions = response.data;
    });

    //通信规约
    getCommunicationProtocol().then((response) => {
      console.log(response);
      this.commProtocolOptions = response.data;
    });

    listUser().then((response) => {
      this.userList = response.rows;
    });

    // 获取设备类型
    listDevModel().then((response) => {
      this.devModelOptions = response.rows;
    });
    // 查询客户
    listCustomer().then((response) => {
      this.customerOptions = response.rows;
    });
    listSimCard().then((response) => {
      this.simCardOptions = response.rows;
    });
    // 设备状态列表
    getDeviceStatus().then((response) => {
      this.devStatusOptions = response.data;
    });
    listArea().then((response) => {
      this.areaOptions = this.handleTree(
        response.data.filter((item) => item.num != 1),
        "num"
      );
    });
    this.getConfigKey("sys:dev:devInfoSource").then((response) => {
      this.devInfoSourceData = response.msg;
    });

    /**通道初始化 */
    // 并网点数据
    listConnectionPoint().then((response) => {
      this.connectionPointOptions = response.rows;
    });
    // 电压等级
    getVolLevel().then((response) => {
      this.voltageLevelOptions = response.data;
    });
    // 接线方式
    getWiringMethod().then((response) => {
      this.wiringMethodOptions = response.data;
    });
    // 接入方式
    getAccessMethod().then((response) => {
      this.accessMethodOptions = response.data;
    });
    // this.getDicts("zk_access_method").then((response) => {
    //   this.accessMethodOptions = response.data;
    // });
    // 额定电压
    getRatedVol().then((response) => {
      this.ratedVoltageOptions = response.data;
    });
    // this.getDicts("zk_rated_voltage").then((response) => {
    //   this.ratedVoltageOptions = response.data;
    // });

    this.getDicts("match_voltage").then((response) => {
      this.matchVoltageOptions = response.data;
    });

    /**cxdz数据初始化 */
    // cxdz告警
    this.getDicts("zk_cxdz_alarm").then((response) => {
      this.cxdzAlarmOption = response.data;
    });
  },
  methods: {
    authorizedDevice() {
      this.authorizeOpen = true;
    },
    handleSelectionChange(data) {
      console.log(data);
      this.authorizedDeviceList = data;
    },
    submitAuthorizedForm() {
      if (!this.authorizeForm.userId) {
        this.$message.error("请选择授权用户");
        return;
      }
      if (this.authorizedDeviceList.length === 0) {
        this.$message.error("请选择设备");
        return;
      }
      let resultList = this.authorizedDeviceList.map((m) => {
        return {
          userId: this.authorizeForm.userId,
          deviceId: m.num,
        };
      });
      addDeviceAuthorized(resultList).then((response) => {
        this.$message.success("授权成功");
        this.$refs.deiveAuthorize.clearSelection();
        this.authorizeOpen = false;
      });
    },
    /**设备方法 */
    //查询设备信息
    getList() {
      this.loading = true;
      getDeviceListFold(this.queryParams).then((res) => {
        this.deviceList = res.rows;
        this.deviceOptions = res.rows; //设置下拉框数据；
        this.total = res.total;
        this.$refs.deiveAuthorize.doLayout();
        this.loading = false;
        console.log(this.deviceOptions);
      });
    },
    // 新增设备
    handleDeviceAdd() {
      this.resetForm("deviceFormDataRef");
      this.deviceFormData.devInfoSource = this.devInfoSourceData;
      this.deviceFormData.connMode = "3";
      this.deviceFormData.storageInterval = 60;
      this.deviceFormData.putDate = new Date();
      this.deviceFormData.communicationProtocolNum = "3";
      this.deviceFormData.communicationStatusNum = "1";
      this.deviceFormData.devStatus = "0";
      this.deviceFormData.sort =
        Number(this.deviceSortOptions[this.deviceSortOptions.length - 1]) + 1;
      this.title = "新增设备";
      this.open = true;
    },
    // 编辑设备
    handleDeviceEdit(row) {
      this.resetForm("deviceFormDataRef");
      this.title = "修改设备";
      this.open = true;
      const num = row.num || this.ids;
      // 根据num获取deviceFormData的数据，为了修改；
      getByNum(num).then((response) => {
        console.log(response.data);

        this.deviceFormData = response.data;
      });
    },
    // 删除设备
    handleDeviceDelete(row) {
      const nums = row.num || this.ids;
      this.$modal
        .confirm("确认删除吗？")
        .then(function () {
          return removeBatch(nums);
        })
        .then(() => {
          this.$modal.msgSuccess("删除成功");
          this.getList();
        })
        .catch(() => {});
    },

    // 查看设备明细
    handleDeviceView(row) {
      this.$router.push({
        path: "/device/device-edit",
        name: "DeviceEdit",
        query: { deviceId: row.num, title: row.devName },
        params: { terminalIdentifier: row.deviceDetails.terminalIdentifier },
      });
    },
    handleSelectChange(val) {
      this.ids = val.map((item) => item.num);
      this.single = this.ids.length !== 1;
      this.multiple = !this.ids.length;
    },
    submitDeviceFormData() {
      this.$refs["deviceFormDataRef"].validate((valid) => {
        if (valid) {
          if (this.deviceFormData.num !== undefined) {
            editDevice(this.deviceFormData).then((response) => {
              this.open = false;
              this.$modal.msgSuccess("修改成功");
              this.getList();
            });
          } else {
            addDevice(this.deviceFormData).then((response) => {
              this.open = false;
              this.$modal.msgSuccess("新增成功");
              this.queryParams.pageNum = Math.ceil(
                this.total / this.queryParams.pageSize
              );
              this.getList();
            });
          }
        }
      });
    },
    deviceClose() {
      this.resetForm("deviceFormDataRef");
      this.open = false;
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleRefresh() {
      this.resetForm("queryParamsRef");
      this.getList();
    },

    /**通道方法 */

    //新增通道
    handelChannelAdd(row) {
      this.resetForm("channelFormDataRef");
      this.channelFormData = {
        deviceNum: row.num,
        wiringMeth: "1",
        accessMode: "0",
        ratedVoltage: "0",
        voltageLevel: "0",

        voltageRatio: 1,
        currentRatio: 1,
        baseShortCirCap: 100,
        minShortCirCap: 0,
        eServAgCap: 0,
        dEquipCap: 0,
        voltageUpperLimit: 110,
        voltageLowerLimit: 90,
        voltageLnterThr: 10,
        matchVoltage: 1,
      };
      this.chInfoSourceData = this.devInfoSourceData + row.devInfoSource + "\\";
      row.channelList.sort((a, b) => a.channelNum - b.channelNum);
      this.channelFormData.channelNum =
        row.channelList[row.channelList.length - 1].channelNum + 1;

      console.log("row", row);
      // 获取排序
      // getSortList(row.num).then((response) => {
      //   this.sortOptions = response.data;
      // });

      this.channelTitle = "新增通道";
      this.channelOpen = true;
      this.cxdzFlag = false;
    },
    /**修改通道 */
    handelChannelEdit(row, row1) {
      // 获取排序
      getSortList(row.deviceNum).then((response) => {
        this.sortOptions = response.data;
      });

      this.cxdzFlag = true;
      this.resetForm("channelFormDataRef");
      const num = row.num || this.ids[0];

      this.chInfoSourceData =
        this.devInfoSourceData + row1.devInfoSource + "\\";

      getChannelByNum(num).then((response) => {
        this.channelTitle = "修改通道";
        this.channelOpen = true;
        this.channelFormData = response.data;
      });

      listCxdz({ tdGuid: row.tdGuid }).then((request) => {
        this.cxdzList = request.data;
      });
    },
    /**删除通道 */
    handelChannelDel(row) {
      const num = row.num || this.ids;
      this.$modal
        .confirm("确认删除吗?")
        .then(function () {
          delChannel(num);
        })
        .then(() => {
          this.$modal.msgSuccess("删除成功");
          this.getList();
          this.channelOpen = false;
        })
        .catch(() => {});
    },
    /**提交表单 */
    submitChannelFormData() {
      this.$refs["channelFormDataRef"].validate((valid) => {
        if (valid) {
          if (this.channelFormData.num != undefined) {
            // 修改
            editChannel(this.channelFormData).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.channelOpen = false;
              this.getList();
            });
          } else {
            // 新增
            addChannel(this.channelFormData).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.channelOpen = false;
              this.getList();
            });
          }
        }
      });
    },
    channelClose() {
      this.channelOpen = false;
    },

    /**cxdz方法 */
    //编辑
    handleCxdzEdit(row) {
      this.resetForm("cxdzFormDataRef");

      // 根据num查询cxdz
      getCxdzByNum(row.num).then((response) => {
        this.cxdzFormData = response.data;
      });
      this.cxdzTitle = row.type == 0 ? "修改一级告警定值" : "修改二级告警定值";
      this.cxdzOpen = true;
    },
    handleCxdzRefresh(row) {
      this.$modal
        .confirm("确认重置吗？")
        .then(function () {
          return refreshCxdz({ num: row.num });
        })
        .then(() => {
          this.$modal.msgSuccess("重置成功！");
          listCxdz(this.cxdzFormData).then((response) => {
            this.cxdzList = response.data;
          });
        })
        .catch(() => {});
    },
    submitCxdzFormData() {
      this.$refs["cxdzFormDataRef"].validate((valid) => {
        if (valid) {
          editCxdz(this.cxdzFormData).then((response) => {
            this.cxdzOpen = false;
            this.$modal.msgSuccess("修改成功！");
            listCxdz(this.cxdzFormData).then((response) => {
              this.cxdzList = response.data;
            });
          });
        }
      });
    },
    cxdzClose() {
      this.cxdzOpen = false;
    },
    getChangeType(e) {
      for (var i = 0; i < this.cxdzAlarmOption.length; i++) {
        if (this.cxdzAlarmOption[i].dictValue == e) {
          //dictValue，dictLabel保持和上面定义一致
          return this.cxdzAlarmOption[i].dictLabel;
        }
      }
    },
    /** 转换地区数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.num,
        label: node.name,
        children: node.children,
      };
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "zk/device/export", //后端接口
        {
          ...this.queryParams, // 参数
        },
        `设备信息_${new Date().getTime()}.xlsx` //导出的文件名称
      );
    },
    handleExpandChange(row) {
      this.chInfoSourceData = this.devInfoSourceData + row.devInfoSource + "\\";
    },
    handleVoltageLevel() {
      this.channelFormData.voltageRatio = this.voltageLevelOptions.filter(
        (item) => item.code == this.channelFormData.voltageLevel
      )[0].volchang;
    },
    // 模拟搜索建议（返回不可选的建议项）
    querySearch(queryString, cb) {
      getDeviceSortList().then((response) => {
        const existingData = response.data.map((item) => String(item.sort));

        const results = existingData.map((item) => ({
          value: item,
          disabled: false, // 标记为不可选（逻辑层标记）
        }));
        cb(results);
      });
    },
    // 阻止选中行为
    handleSelect(item) {
      if (item.disabled) {
        this.$modal.msgError("不可选择已有项，请手动输入！");
        this.deviceFormData.sort = ""; // 清空输入（或恢复原值）
        return false; // 阻止默认选中
      }
    },
    // 校验排序是否存在的方法
    validateSortExistence: (rule, value, callback) => {
      // if (!value) {
      //   callback(new Error('请输入排序值'));
      //   return;
      // }
      // getDeviceSortList().then(response => {
      //   const existingData = response.data.map(item => String(item.sort))

      //   if (existingData.includes(value)) {
      //     callback(new Error('该排序值已存在，请重新输入！'));
      //   } else {
      //     callback(); // 校验通过
      //   }
      // })
      callback();
    },
  },
};
</script>

<style lang="scss" scoped>
.autocomplete-item-disabled {
  color: #999;
  cursor: not-allowed;
  pointer-events: none;
  /* 禁止点击 */
}

/* 默认隐藏操作列 */
.operation-column {
  visibility: hidden;
}

/* 当鼠标悬停在行上时显示操作列 */
.el-table__row:hover .operation-column {
  visibility: visible;
}

/* 确保按钮在列显示时可见 */
.operation-buttons {
  white-space: nowrap;
}
</style>
